package com.snjgm.chapter1_alogimic;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.snjgm.chapter1_alogimic.util.DateUtil;


//数据接收方
public class ReciveActivity extends AppCompatActivity implements View.OnClickListener {

    private static final String TAG = "reciveActivity";
    private TextView tv_rcv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recive);
        tv_rcv=  findViewById(R.id.tv_rcv);
        Bundle bundle = getIntent().getExtras();
        String requestTime = bundle.getString("request_time");
        String requestPlace = bundle.getString("request_place");
        String information = String.format("收到请求消息:+\n请求时间为%s\n请求内容为%s",requestTime,requestPlace);
        tv_rcv.setText(information);
        findViewById(R.id.btn_rcv).setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        Intent intent = new Intent(this, SendActivity.class);
        Bundle bundle = new Bundle();
        Log.d(TAG, "onClick: getNowDate: "+bundle);
        bundle.putString("response_time", DateUtil.getNowDate());
        bundle.putString("response_content","这里是返回的数据");
        intent.putExtras(bundle);
        setResult(Activity.RESULT_OK,intent);
        finish();
    }
}